package com.example.light.common.result;

public class Result<T> {
    private String msg;
    private int code;
    private T data;

    public Result(T data) {
        this.data = data;
    }

    public Result(String msg, int code) {
        this.msg = msg;
        this.code = code;
    }

    public Result(String msg, int code, T data) {
        this.msg = msg;
        this.code = code;
        this.data = data;
    }

    public Result() {
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(CodeMsg.SystemCodeMsg.SUCCESS.getMsg(), CodeMsg.SystemCodeMsg.SUCCESS.getCode(), data);
    }

    public static <T> Result<T> success() {
        return new Result<>(CodeMsg.SystemCodeMsg.SUCCESS.getMsg(), CodeMsg.SystemCodeMsg.SUCCESS.getCode());
    }

    public static <T> Result<T> error(CodeMsg codeMsg) {
        if (codeMsg != null) {
            return new Result<>(codeMsg.getMsg(),
                    codeMsg.getCode());
        }
        return new Result(CodeMsg.SystemCodeMsg.ERROR.getMsg(), CodeMsg.SystemCodeMsg.ERROR.getCode());
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
